<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>首页</title>
<!-- bootstrap样式、主题、核心文档 -->
<link rel="stylesheet" href="libs/bootstrap-3.3.7-dist/bootstrap-3.3.7-dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="libs/bootstrap-3.3.7-dist/bootstrap-3.3.7-dist/css/bootstrap-theme.min.css" />
<script type="text/javascript" src="libs/bootstrap-3.3.7-dist/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
<script type="text/javascript" src="libs/jquery/jquery.js"></script>
<script type="text/javascript">
	$(function(){
		username = "${user.username}";
		$("iframe").css("height",window.screen.availHeight*12/19);
		$("div.container>ul>li").eq(1).click(function(){
			//alert(username);
			if(username==""){
				alert("请先登录");
				$("iframe").eq(0).attr("src","login.jsp");
			}else{
				//$("iframe").eq(0).attr("src","borrow.html");
				//是否已经有借款信息
				var userid = "${user.id}";
				
				$.ajax({
					type:"post",
					url:"UserLoanbillServlet",
					data:"id="+userid,
					dataType:"json",
					success:function(result){
						if(result.flag==true){//可以再借
							$("iframe").eq(0).attr("src","user/borrow.jsp");
						}else{//借款信息已失效或者借款已还清，可以再次借款(借款信息生效)
							//展示个人的借款信息，状态
							$("iframe").eq(0).attr("src","user/showborrowinfo.jsp");
						}
					}
				});
				
			}
		});
		$("div.container>ul>li").eq(2).click(function(){
			if(username==""){
				alert("请先登录");
				$("iframe").eq(0).attr("src","login.jsp");
			}else{
				$("iframe").eq(0).attr("src","user/lend.jsp");
			}
		});
		$("div.container>ul>li").eq(6).click(function(){
			if(username==""){
				$("iframe").eq(0).attr("src","register.html");
			}else{
				//ajax完成退出的功能
				$.post("LogoutServlet",function(result){
					alert(result.message);
					$("iframe").eq(0).attr("src","welcome.html");
					location.reload();
				},"json");
				
			}
		});
		$("div.container>ul>li").eq(5).on('click',function(){
			$("iframe").eq(0).attr("src","login.jsp");
		});
		
		
		if(username==""){
			$("#li6").html("登录");
			$("#li7").html("注册");
		}else{
			$("#li6").html(username);
			$("#li7").html("<span class='glyphicon glyphicon-log-out' aria-hidden='true'></span>");
			$("iframe").eq(0).attr("src","welcome.html");
			$("div.container>ul>li").eq(5).off();
			$("div.container>ul>li").eq(5).on("click",function(){
				$("iframe").eq(0).attr("src","user/personal.jsp");
			});
		}
	})

</script>
<style type="text/css">
	ul{
		
		font-size: 20px;
	}
	ul>li:hover{
		cursor: pointer;	
	}
	.nav>li{
		width:150px;
		position: relative;
		float: left;
		margin: 0;
		margin-top: 20px;
		}
	.page-header{
		margin-top: -5px;
	}
	iframe{
		min-height: 480px;
	}
	#li{
		text-align: left;
		width:225px;
		padding: 0;
		margin: 0;
	}
</style>
</head>
<body>
<div class="container">
	<ul class="nav nav-pills nav-justified">
	  <li role="presentation" id="li"><img src="images/cxd.jpg" width="170px"/></li>
	  <li role="presentation"><a>我要借钱</a></li>
	  <li role="presentation"><a>我要出借</a></li>
	  <li role="presentation"><a>信息公告</a></li>
	  <li role="presentation"><a>帮助</a></li>
	  <li role="presentation"><a id="li6">登录</a></li>
	  <li role="presentation"><a id="li7">注册</a></li>
	</ul>
	
	<div class="page-header" style="background-color: WhiteSmoke; ">
	  <h1>让钱活起来&nbsp;&nbsp;<small>"贷"来好运</small></h1>
	</div>
	<iframe src="welcome.html" style="width:100%; border: none; height: 480px; padding: 0" >
	
	</iframe>
	<nav class="navbar navbar-default navbar-fixed-bottom container">
		<div class="container" style="text-align: center; margin-top: 15px;">
			京ICP备11008151号京公网安备11010802014853
		</div>
	</nav>
	</div>
</body>
</html>